package com.cloud.job;

import com.cloud.Enum.ConsumerTypeEnum;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableScheduling
public class JobConditionConfiguration implements Condition {

    //consumerType等于2，3,4才开启定时任务
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        String consumerType = context.getEnvironment().getProperty("cloud.joyoung.log.consumer-type");
        return ConsumerTypeEnum.COMMON_FEIGN.getCode().equals(consumerType) || ConsumerTypeEnum.BRIDGE_FEIGN.getCode().equals(consumerType) || ConsumerTypeEnum.HTTPCLIENT.getCode().equals(consumerType);
    }
}